/*******************************************************************************
  ARTICLE	GAY, GOBBI, GONI (2025) "REVOLUTIONARY TRANSITIONS. INHERITANCE    
            CHANGE AND FERTILITY DECLINE" JOURNAL OF POLITICAL ECONOMY         
                                                                               
  AUTHORS	VICTOR GAY, PAULA GOBBI, MARC GONI                                 
  CONTACT	victor.gay@tse-fr.eu; paula.eugenia.gobbi@ulb.be; marc.goni@uib.no 
  VERSION	1.0 (MAY 2025)                                                     
  SOFTWARE	STATA SE 18                                                        
  LICENCE	MIT                                                                
--------------------------------------------------------------------------------

AGRICULTURAL CENSUS RESULTS DO FILE

This file contains the codes to reproduce the figures and tables in Appendix F
using the agricultural census data.

Instructions: 
-------------
	open do-files from directory where they are placed; order matters; run whole code.

Contents: 
---------
	Table F4: Summary statistics for soil and land characteristics.
	Figure F9: Farming land structure and soil characteristics.
	Table F5: Soil characteristics and farm size in 1852.
	
Date last update: May 2025; Ran using STATA 18.5
*/
********************************************************************************

********************
* 0. PROGRAM SETUP *
********************

version 18
clear all
set more off

************************
* PACKAGE DEPENDENCIES *
************************

ssc install reghdfe, replace
ssc install ftools, replace
ssc install binscatter, replace

***************
* DIRECTORIES *
***************

global DAT 	= "../../3_outputs/3_1_datasets"
global APPTAB 	= "../../3_outputs/3_3_appendix/3_3_1_appendix_tables"
global APPFIG 	= "../../3_outputs/3_3_appendix/3_3_2_appendix_figures"
global TEMP = "../2_0_tempfiles"

timer on 1

* ==============================================================================
* Table F4: Summary statistics for soil and land characteristics
* ------------------------------------------------------------------------------

use "$DAT/agricensus.dta", clear
summarize ruggedness sh_sandy av_farm_size_1 av_farm_size_2 coast river mountain
* ==============================================================================

* ==============================================================================
* Figure F9: Farming land structure and soil characteristics
* ------------------------------------------------------------------------------

use "$DAT/agricensus.dta", clear

* ARABLE LAND AND RUGGEDNESS

binscatter av_farm_size_1 ruggedness,   linetype(lfit)                       ///
	xtitle("Ruggedness (100m)", size(12-pt) height(6))                       ///
	ytitle("Farm size (arable ha / landowner)", size(12-pt) height(6))       ///
	yscale(range(0(3)13)) yticks(0(3)13) ylabel(0(3)13)                      ///
	xscale(range(0(1)5)) xticks(0(1)5) xlabel(0(1)5)                         ///
	graphregion(fcolor(white) lcolor(white)) plotregion(fcolor(white)        ///
	lcolor(black))
graph export "$APPFIG/figureF9a.pdf", as(pdf) replace

* ARABLE LAND AND SANDINESS

binscatter av_farm_size_1 sh_sandy,   linetype(lfit)                         ///
	xtitle("Share sandy soil", size(12-pt) height(6))                        ///
	ytitle("Farm size (arable ha / landowner)", size(12-pt) height(6))       ///
	yscale(range(0(3)13)) yticks(0(3)13) ylabel(0(3)13)                      ///
	xscale(range(0(0.2)1)) xticks(0(0.2)1) xlabel(0(0.2)1)                   ///
	graphregion(fcolor(white) lcolor(white)) plotregion(fcolor(white)        ///
	lcolor(black))
graph export "$APPFIG/figureF9b.pdf", as(pdf) replace
	
* CULTIVATED LAND AND RUGGEDNESS

binscatter av_farm_size_2 ruggedness,   linetype(lfit)                       ///
	xtitle("Ruggedness (100m)", size(12-pt) height(6))                       ///
	ytitle("Farm size (arable ha / landowner)", size(12-pt) height(6))       ///
	yscale(range(0(3)13)) yticks(0(3)13) ylabel(0(3)13)                      ///
	xscale(range(0(1)5)) xticks(0(1)5) xlabel(0(1)5)                         ///
	graphregion(fcolor(white) lcolor(white)) plotregion(fcolor(white)        ///
	lcolor(black))
graph export "$APPFIG/figureF9c.pdf", as(pdf) replace

* CULTIVATED LAND AND SANDINESS

binscatter av_farm_size_2 sh_sandy,   linetype(lfit)                         ///
	xtitle("Share sandy soil", size(12-pt) height(6))                        ///
	ytitle("Farm size (arable ha / landowner)", size(12-pt) height(6))       ///
	yscale(range(0(3)13)) yticks(0(3)13) ylabel(0(3)13)                      ///
	xscale(range(0(0.2)1)) xticks(0(0.2)1) xlabel(0(0.2)1)                   ///
	graphregion(fcolor(white) lcolor(white)) plotregion(fcolor(white)        ///
	lcolor(black))
graph export "$APPFIG/figureF9d.pdf", as(pdf) replace
* ==============================================================================

* ==============================================================================
* Table F5: Soil characteristics and farm size in 1852
* ------------------------------------------------------------------------------

use "$DAT/agricensus.dta", clear

/* controls */
local controls "i.mountain i.coast i.river"

* PANEL A

/* column 1 */
reghdfe av_farm_size_1 ruggedness, absorb(dep_name) cluster(dep_name)

/* column 2 */
reghdfe av_farm_size_1 sh_sandy, absorb(dep_name) cluster(dep_name)

/* column 3 */
reghdfe av_farm_size_1 ruggedness sh_sandy, absorb(dep_name) cluster(dep_name)

/* column 4 */
reghdfe av_farm_size_1 ruggedness sh_sandy `controls', absorb(dep_name) cluster(dep_name)

* PANEL B

/* column 1 */
reghdfe av_farm_size_2 ruggedness, absorb(dep_name) cluster(dep_name)

/* column 2 */
reghdfe av_farm_size_2 sh_sandy, absorb(dep_name) cluster(dep_name)

/* column 3 */
reghdfe av_farm_size_2 ruggedness sh_sandy, absorb(dep_name) cluster(dep_name)

/* column 4 */
reghdfe av_farm_size_2 ruggedness sh_sandy `controls', absorb(dep_name) cluster(dep_name)
* ==============================================================================

timer off 1 /* 3 seconds */
timer list